function getUser() {
    $.ajax({
        type: 'get',
        url: '/my/userinfo',
        success: function (res) {
            console.log(res);
            if (res.status !== 0) return layui.layer.msg(res.message);
            // layui.layer.msg(res.message);
            // console.log(res);
            readyUser(res.data);
        }
        
    });
}
getUser();

function readyUser(user) {
    let name = user.nickname || user.username;
    // console.log(name[0].toUpperCase());
    $('#welcome').html(`欢迎回来${name}`);
    if (user.user_pic) {
        // console.log(1);
        $(".layui-nav-img").attr('src', user.user_pic);
        $(".layui-nav-img").show().siblings('.text-avatar').hide();

    } else {
        $(".layui-nav-img").hide().siblings('.text-avatar').html(name[0].toUpperCase()).show();
    }
}
const layer = layui.layer;

$("#btn-tuichu").on('click', function () {
    layer.confirm('确定退出登录?', {
        icon: 3,
        title: '提示'
    }, function (index) {
        sessionStorage.removeItem('token');
        location.href='/login.html'
        layer.close(index)
    })
})